package com.pl.arithmetic.link;

import com.pl.arithmetic.dto.HeroNode;

/**
 * <p>
 *
 * @Description: TODO
 * </p>
 * @ClassName SingleLinkList
 * @Author pl
 * @Date 2020/4/17
 * @Version V1.0.0
 */
public class SingleLinkList {

    private HeroNode headNode = new HeroNode(0,"","");

    public void add(HeroNode heroNode){
        HeroNode indexNode = headNode;
        while (indexNode.next != null){
            indexNode = indexNode.next;
        }
        indexNode.next = heroNode;
    }

    public void list(){
        if(headNode.next == null) {
            System.out.println("链表为空");
            return;
        }
        //因为头节点，不能动，因此我们需要一个辅助变量来遍历
        HeroNode temp = headNode.next;

        while (temp.next!=null){
            System.out.println(temp);
            temp= temp.next;
        }
        System.out.println("尾节点"+temp);
    }
}